package com.uinnova.product.eam.mvc;

import com.binary.framework.web.RemoteResult;
import com.uinnova.product.eam.service.CasLoginService;
import com.uinnova.product.vmdb.comm.doc.annotation.ModDesc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 国投单点登录接口
 * @author: LiMG
 * @create: 2024-05-28 11:20:31
 **/
@RestController
@RequestMapping("/casLogin")
@ConditionalOnProperty(name = "monet.login.loginMethod", havingValue = "guotouiam")
public class CASLoginController {

    @Autowired
    private CasLoginService casLoginService;

    @GetMapping("/getJumpLoginUrl")
    public RemoteResult getJumpLoginUrl() {
        return new RemoteResult(casLoginService.getJumpLoginUrl());
    }

    @GetMapping("/getJumpLogoutUrl")
    public RemoteResult getJumpLogoutUrl() {
        return new RemoteResult(casLoginService.getJumpLogoutUrl());
    }

    @GetMapping("/checkLoginTicket")
    @ModDesc(desc = "国投IAM验证登录票据", pDesc = "", rDesc = "true-成功，false-失败", rType = RemoteResult.class)
    public void checkLoginToken(@RequestParam("ticket") String ticket,
                                @RequestParam("goPageUrl") String goPageUrl,
                                HttpServletRequest request, HttpServletResponse response) throws IOException {
        casLoginService.checkLoginTicket(ticket, goPageUrl, request, response);
    }

    @RequestMapping("/ticketLogout")
    public void ticketLogout(@RequestParam(value = "tk", required = false) String ticket,
                             @RequestParam(value = "type", required = false) Integer type,
                             HttpServletResponse response) throws IOException {
        casLoginService.ticketLogout(ticket, type, response);
    }

}
